<?php

class AesHelper
{
    /*** 加密 * @param String input 加密的字符串 * @param String key 解密的 key * @return HexString */
    public static function encrypt($data, $key)
    {
        $data = openssl_encrypt($data, 'AES-128-ECB', base64_decode($key), OPENSSL_RAW_DATA);
        return base64_encode($data);
    }


    public static function decrypt($data, $key)
    {
        $encrypted = base64_decode($data);
        return openssl_decrypt($encrypted, 'AES-128-ECB', base64_decode($key), OPENSSL_RAW_DATA);
    }

    public static function getMode($key)
    {
        if (strlen($key) === 32) {
             $mode = 'AES-256-ECB'; } elseif (strlen($key) === 24) {
            $mode = 'AES-192-ECB';
        } else {
            $mode = 'AES-128-ECB';
        }
        return $mode;
    }
}
